package nc.impl.gsp.pub.record;

import java.util.ArrayList;
import java.util.List;

import nc.bs.dao.BaseDAO;
import nc.itf.gsp.pub.record.IRecord;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.gsp.pub.record.purchase.RecordPurchaseHeadVO;
import nc.vo.gsp.pub.record.receive.RecordReceiveHeadVO;
import nc.vo.gsp.pub.record.review.RecordReviewHeadVO;
import nc.vo.gsp.pub.record.sales.RecordSalesHeadVO;
import nc.vo.jcom.lang.StringUtil;

public class IRecordImpl implements IRecord {

	public RecordPurchaseHeadVO[] queryRecordPurchase(String strWhere)
			throws Exception {

		StringBuffer sql = new StringBuffer("select distinct gsp_r_purchase.* ");
		sql.append(" from gsp_r_purchase ");
		sql
				.append(" inner join med_invbasdoc on gsp_r_purchase.pk_invbasdoc=med_invbasdoc.pk_invbasdoc ");
		sql.append(" where gsp_r_purchase.dr=0 and med_invbasdoc.dr=0 ");
		if (!StringUtil.isEmptyWithTrim(strWhere)) {
			sql.append(" and (").append(strWhere).append(")");
		}
		RecordPurchaseHeadVO[] rs = null;
		List list = (ArrayList) new BaseDAO().executeQuery(sql.toString(),
				new BeanListProcessor(RecordPurchaseHeadVO.class));
		if (list != null) {
			rs = (RecordPurchaseHeadVO[]) list
					.toArray(new RecordPurchaseHeadVO[list.size()]);
		}
		return rs;
	}

	public RecordReceiveHeadVO[] queryRecordReceive(String strWhere)
			throws Exception {

		StringBuffer sql = new StringBuffer("select distinct gsp_r_receive.* ");
		sql.append(" from gsp_r_receive ");
		sql
				.append(" inner join med_invbasdoc on gsp_r_receive.pk_invbasdoc=med_invbasdoc.pk_invbasdoc ");
		sql.append(" where gsp_r_receive.dr=0 and med_invbasdoc.dr=0 ");
		if (!StringUtil.isEmptyWithTrim(strWhere)) {
			sql.append(" and (").append(strWhere).append(")");
		}
		RecordReceiveHeadVO[] rs = null;
		List list = (ArrayList) new BaseDAO().executeQuery(sql.toString(),
				new BeanListProcessor(RecordReceiveHeadVO.class));
		if (list != null) {
			rs = (RecordReceiveHeadVO[]) list
					.toArray(new RecordReceiveHeadVO[list.size()]);
		}
		return rs;
	}

	public RecordReviewHeadVO[] queryRecordReview(String strWhere)
			throws Exception {
		StringBuffer sql = new StringBuffer("select distinct gsp_r_review.* ");
		sql.append(" from gsp_r_review ");
		sql
				.append(" inner join med_invbasdoc on gsp_r_review.pk_invbasdoc=med_invbasdoc.pk_invbasdoc ");
		sql.append(" where gsp_r_review.dr=0 and med_invbasdoc.dr=0 ");
		if (!StringUtil.isEmptyWithTrim(strWhere)) {
			sql.append(" and (").append(strWhere).append(")");
		}
		RecordReviewHeadVO[] rs = null;
		List list = (ArrayList) new BaseDAO().executeQuery(sql.toString(),
				new BeanListProcessor(RecordReviewHeadVO.class));
		if (list != null) {
			rs = (RecordReviewHeadVO[]) list
					.toArray(new RecordReviewHeadVO[list.size()]);
		}
		return rs;
	}

	public RecordSalesHeadVO[] queryRecordSales(String strWhere)
			throws Exception {
		StringBuffer sql = new StringBuffer("select distinct gsp_r_sales.* ");
		sql.append(" from gsp_r_sales ");
		sql
				.append(" inner join med_invbasdoc on gsp_r_sales.pk_invbasdoc=med_invbasdoc.pk_invbasdoc ");
		sql.append(" where gsp_r_sales.dr=0 and med_invbasdoc.dr=0 ");
		if (!StringUtil.isEmptyWithTrim(strWhere)) {
			sql.append(" and (").append(strWhere).append(")");
		}
		RecordSalesHeadVO[] rs = null;
		List list = (ArrayList) new BaseDAO().executeQuery(sql.toString(),
				new BeanListProcessor(RecordSalesHeadVO.class));
		if (list != null) {
			rs = (RecordSalesHeadVO[]) list.toArray(new RecordSalesHeadVO[list
					.size()]);
		}
		return rs;
	}

}
